<?php

include_once("functions/db_manipulate.php");
if (!init()) {
    redirect('login.php');
}

$link_id = connectDB();

if ($_GET['like'] != '') {
    $checkLikeResultSet = mysql_query("INSERT INTO likes(userid, indicator, contentid)
                                       VALUES (
                                               '" . $_SESSION['id'] . "',
                                               'i',
                                               '" . $_GET['iid'] . "')");
    if ($checkLikeResultSet) {
        $resultSet = mysql_query("UPDATE gallery SET `like` = `like` + 1
                              WHERE
                                     id='" . mysql_real_escape_string($_GET['iid']) . "'") or die(mysql_error());
    }
} else if ($_GET['dislike'] != '') {
    $checkDislikeResultSet = mysql_query("INSERT INTO dislikes(userid, indicator, contentid)
                                       VALUES (
                                               '" . $_SESSION['id'] . "',
                                               'i',
                                               '" . $_GET['iid'] . "')");
    if ($checkDislikeResultSet) {
        $resultSet = mysql_query("UPDATE gallery SET `dislike` = `dislike` + 1
                              WHERE
                                     id='" . mysql_real_escape_string($_GET['iid']) . "'") or die(mysql_error());
    }
}

redirect($_SERVER['HTTP_REFERER']);
